package net.e4net.watrix.action.join;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.e4net.watrix.ActionResponse;
import net.e4net.watrix.ResponseData;
import net.e4net.watrix.WatrixContext;
import net.e4net.watrix.WatrixException;
import net.e4net.watrix.base.member.MemberVO;
import net.e4net.watrix.common.hao.RequestParser;
import net.e4net.watrix.common.tao.TaoConnection;
import net.e4net.watrix.common.tao.TaoDataSet;
import net.e4net.watrix.common.tao.TaoResult;
import net.e4net.watrix.example.base.ExamConstants;
import net.e4net.watrix.runtime.AbstractAction;
import net.e4net.watrix.runtime.ActionException;


@SuppressWarnings("serial")
public class idCheckActn extends AbstractAction {

	@Override
	public ActionResponse execute(WatrixContext context, HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException,
			WatrixException {
		// TODO Auto-generated method stub
		RequestParser parser = context.getRequestParser("default",request,response);
		String id = parser.getParameter("ID");
		
		ResponseData data = super.getResponseData(request);
		TaoConnection con = null;
		
		TaoResult result = null;
		
		try{
			con = context.getTaoConnection("default",null);
			TaoDataSet dataset = TaoDataSet.getInstance();
			
			dataset.setString("ID", id);
			
			result = con.execute("net.e4net.watrix.proc.join.idCheckProc", dataset);
			
			if(result.rows() == 0){
				data.put("idcheck", "pass");
			}
			else{
				data.put("idcheck", "failure");
			}
			data.put("test", "test");
			data.put("ID", id);
			
		}catch(Throwable t){
			throw new ActionException(this.getActionDesc(context),
					context.getMessage(ExamConstants.SYSTEM_ERROR,null),t);
		}finally{
			try{con.close();}catch(Throwable ignore){}
		}
			
		return super.getActionResponse(context);
	}
		
}